using MediatR;
using Zhaoxi.Zhihu.Core.AppUserAggregate.Event;
using Zhaoxi.Zhihu.Core.QuestionAggregate.Entites;
using Zhaoxi.Zhihu.SharedKerel.Repositoy;

namespace Zhaoxi.Zhihu.Core.QuestionAggregate.Handler;

public class FollowQuestionRemoveEventHandler(IRepository<Question> questions):INotificationHandler<FollowQuestionRemovedEvent>
{
    public  async Task Handle(FollowQuestionRemovedEvent notification, CancellationToken cancellationToken)
    {
        var question = await questions.GetByIdAsync(notification.FollowQuestion.QuestionId,cancellationToken);
        
        if (question is null)return;
        question.FollowCount -= 1;
        await questions.SaveChangesAsync(cancellationToken);
    }
}